package com.sui.bigdata.rtcadmin.dto;

import com.alibaba.fastjson.annotation.JSONField;
import com.sui.bigdata.rtcadmin.repository.model.JobConfig;
import com.sui.bigdata.rtcadmin.util.DateUtils;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * @author YongChen
 * @date 2019/11/6 14:41
 * @description
 * @email yong_chen@sui.com
 */
@Data
@Accessors(chain = true)
public class JobConfigDto {

    @JSONField(name = "jobName")
    private String jobName;
    @JSONField(name = "developer")
    private String developer;
    @JSONField(name = "alarmGroupPhone")
    private String alarmGroupPhone;
    @JSONField(name = "execSql")
    private String execSql;
    @JSONField(name = "appId")
    private String appId;
    @JSONField(name = "parallelism")
    private int parallelism;
    @JSONField(name = "queue")
    private String queue;
    @JSONField(name = "jobManagerMemory")
    private int jobManagerMemory;
    @JSONField(name = "taskManagerMemory")
    private int taskManagerMemory;
    @JSONField(name = "slots")
    private int slots;
    @JSONField(name = "extendParam")
    private String extendParam;
    @JSONField(name = "description")
    private String description;
    @JSONField(name = "status")
    private String status;
    @JSONField(name = "webUrl")
    private String webUrl;
    @JSONField(name = "savePointPath")
    private String savePointPath;
    @JSONField(name = "createTime")
    private String createTime;
    @JSONField(name = "updateTime")
    private String updateTime;
    @JSONField(name = "startTime")
    private String startTime;
    @JSONField(name = "endTime")
    private String endTime;
    @JSONField(name = "runningTime")
    private String runningTime;
    @JSONField(name = "savepoint")
    private Boolean savepoint;
    @JSONField(name = "isOnline")
    private int isOnline;

    public static JobConfigDto buildJobConfigDto(JobConfig jobConfig){
        if (jobConfig == null){
            return null;
        }
        return new JobConfigDto()
                .setJobName(jobConfig.getJobName())
                .setDeveloper(jobConfig.getDeveloper())
                .setAlarmGroupPhone(jobConfig.getAlarmGroupPhone())
                .setExecSql(jobConfig.getExecSql())
                .setAppId(jobConfig.getAppId())
                .setParallelism(jobConfig.getParallelism())
                .setQueue(jobConfig.getQueue())
                .setJobManagerMemory(jobConfig.getJobManagerMemory())
                .setTaskManagerMemory(jobConfig.getTaskManagerMemory())
                .setSlots(jobConfig.getSlots())
                .setExtendParam(jobConfig.getExtendParam())
                .setDescription(jobConfig.getDescription())
                .setStatus(jobConfig.getStatus())
                .setWebUrl(jobConfig.getWebUrl())
                .setCreateTime(DateUtils.formatDate(jobConfig.getCreateTime(),DateUtils.YYYY_MM_DD_HH_MM_SS))
                .setUpdateTime(DateUtils.formatDate(jobConfig.getUpdateTime(),DateUtils.YYYY_MM_DD_HH_MM_SS))
                .setRunningTime(DateUtils.getDifferentTime(jobConfig.getCreateTime(),new Date()))
                .setIsOnline(jobConfig.getIsOnline());
    }

    @Override
    public String toString() {
        return "JobConfigDto{" +
                "jobName='" + jobName + '\'' +
                ", execSql='" + execSql + '\'' +
                ", parallelism=" + parallelism +
                ", queue='" + queue + '\'' +
                ", jobManagerMemory=" + jobManagerMemory +
                ", taskManagerMemory=" + taskManagerMemory +
                ", slots=" + slots +
                ", extendParam='" + extendParam + '\'' +
                ", status='" + status + '\'' +
                ", webUrl='" + webUrl + '\'' +
                ", savePointPath='" + savePointPath + '\'' +
                ", startTime='" + createTime + '\'' +
                ", updateTime='" + updateTime + '\'' +
                ", runningTime='" + runningTime + '\'' +
                ", isOnline='" + isOnline + '\'' +
                '}';
    }
}
